using System;
using mojoPortal.Web;
using mojoPortal.Web.Framework;
using Resources;

namespace ud_SwirlingQuestion
{
    public partial class SwirlingQuestionModule : SiteModuleControl
    {
        private SwirlingQuestionConfiguration config = new SwirlingQuestionConfiguration();
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Load += Page_Load;
            EnableViewState = false;
        }

        protected virtual void Page_Load(object sender, EventArgs e)
        {
            LoadSettings();
            PopulateLabels();
            PopulateControls();
        }

        private void PopulateControls()
        {
            if (config.ShowSearchPlace)
            {
                SearchPlace.Config = config;
                SearchPlace.PageId = PageId;
                SearchPlace.ModuleId = ModuleId;
                SearchPlace.SiteRoot = SiteRoot;
            }
            QuestionList.ModuleId = ModuleId;
            QuestionList.PageId = PageId;
            QuestionList.Config = config;
            QuestionList.SiteRoot = SiteRoot;
            QuestionList.ImageSiteRoot = ImageSiteRoot;
            QuestionList.IsEditable = IsEditable;
        }

        protected virtual void PopulateLabels()
        {
            Title1.EditText = SwirlingQuestionResource.ButtonEdit;
            Title1.EditUrl = SiteRoot + "/SwirlingQuestion/Admin/SwirlingQuestionEdit.aspx";
            Title1.ShowEditLinkOverride = false;
            if (config.UsePostQuestionInTitleControlSetting)
            {
                Title1.LiteralExtraMarkup =
                    "&nbsp;<a href='"
                    + SiteRoot
                    + "/SwirlingQuestion/PostQuestion.aspx?pageid=" + PageId.ToInvariantString()
                    + "&amp;mid=" + ModuleId.ToInvariantString()
                    + "' class='ModuleEditLink' title='" + SwirlingQuestionResource.AddQuestionLabel +
                    "'><img src='/Data/Icon16x16/Modify.png' alt='" + SwirlingQuestionResource.AddQuestionLabel +
                    " |'</img></a>";
            }
        }

        protected virtual void LoadSettings()
        {
            pnlContainer.ModuleId = ModuleId;
            config = new SwirlingQuestionConfiguration(Settings);
            if (!config.CustomCssClass.Equals(string.Empty)) { pnlContainer.CssClass += " " + config.CustomCssClass; }
            SearchPlace.Visible = config.ShowSearchPlace;
        }

    }
}
